import time
import yaml
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from page.basePage import basePage

with open(r'D:\PycharmProjects\ecShop\autoTest\driver\elements.yml','r',encoding='utf-8') as file:
    elements_config = yaml.safe_load(file)

class addspct1Page(basePage):
    url = "http://localhost:8800/ecshop/"
    login_btn1 = By.XPATH, elements_config['login_page']['login_btn1']
    username_frm = By.XPATH, elements_config['login_page']['username_frm']
    pwd_frm = By.XPATH, elements_config['login_page']['pwd_frm']
    login_btn2 = By.XPATH, elements_config['login_page']['login_btn2']

    commodity_btn = By.XPATH,elements_config['addspct1_page']['commodity_btn']
    count_frm = By.ID, elements_config['addspct1_page']['count_frm']
    add_btn = By.XPATH,elements_config['addspct1_page']['add_btn']
    checkout_btn = By.XPATH,elements_config['addspct1_page']['checkout_btn']

    tjdd_btn = By.XPATH,elements_config['addspct1_page']['tjdd_btn']
    def click_login1(self):
        self.find_Element(self.login_btn1).click()

    def send_username(self,username):
        self.find_Element(self.username_frm).send_keys(username)

    def send_pwd(self,password):
        self.find_Element(self.pwd_frm).send_keys(password)

    def click_login2(self):
        self.find_Element(self.login_btn2).click()

    def click_commodity(self):
        self.find_Element(self.commodity_btn).click()

    def click_add(self):
        self.find_Element(self.add_btn).click()

    def send_count(self,count):
        self.find_Element(self.count_frm).send_keys(count)

    def click_checkout(self):
        self.find_Element(self.checkout_btn).click()

    def click_tj(self):
        self.find_Element(self.tjdd_btn).click()

    def fun_addspct1(self,username,password,count):
        self.open(self.url)
        self.click_login1()
        self.send_username(username)
        self.send_pwd(password)
        self.click_login2()
        time.sleep(5)

        self.click_commodity()
        time.sleep(1)
        self.send_count(count)
        self.click_add()
        time.sleep(2)
        self.click_checkout()
        time.sleep(1)
        self.click_tj()




